﻿using System;
using System.Collections.Generic;

using HL.Core.Models;

namespace HL.Lib.Models
{
    public class ModPropertyEntity : EntityBase
    {
        
        #region Autogen by HL

        [DataInfo]
        public override int ID { get; set; }

        [DataInfo]
        public int ParentID { get; set; }

        [DataInfo]
        public override string Name { get; set; }

        [DataInfo]
        public int Order { get; set; }

        #endregion

        public List<ModPropertyEntity> GetChildByParentID(string nid)
        {
            return ModPropertyService.Instance.CreateQuery()
               .Where(o => o.ParentID == ID)
               .WhereNotIn(!string.IsNullOrEmpty(nid),o=>o.ID,nid)
               .ToList_Cache();
        }

        public List<ModPropertyEntity> GetChildByParentID()
        {
            return ModPropertyService.Instance.CreateQuery()
               .Where(o => o.ParentID == ID)
               .ToList_Cache();
        }
    }

    public class ModPropertyService : ServiceBase<ModPropertyEntity>
    {

        #region Autogen by HL

        private ModPropertyService()
            : base("[Mod_Property]")
        {

        }

        private static ModPropertyService _Instance = null;
        public static ModPropertyService Instance
        {
            get
            {
                if (_Instance == null)
                    _Instance = new ModPropertyService();

                return _Instance;
            }
        }

        #endregion

        public ModPropertyEntity GetByID(int id)
        {
            return base.CreateQuery()
               .Where(o => o.ID == id)
               .ToSingle();
        }
        public List<ModPropertyEntity> GetChildByParentID(int id)
        {
            return ModPropertyService.Instance.CreateQuery()
               .Where(o => o.ParentID == id).ToList();
        }
    }
}